<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(words) {
      let res = [];
      const check = (str) => {
        for (let i = 0, j = str.length - 1; i < j; i++, j--) {
          if (str[i] !== str[j]) {
            return false;
          }
        }
        return true;
      };
      for (let i = 0; i < words.length; i++) {
        for (let j = i + 1; j < words.length; j++) {
          if (check(words[i] + words[j])) {
            res.push([i, j]);
          }
          if (check(words[j] + words[i])) {
            res.push([j, i]);
          }
        }
      }
      return res;
    };
    console.log(arr(["abcd", "dcba", "lls", "s", "sssll"]));
  </script>
</body>

</html>